<style>
    #fairy-sku-table .uploadimage{
        width: 56px !important;
        height: 56px !important;
    }
    .attr-left {
        border-left: solid 5px #008aff;
        font-size: 14px;
        margin-right: 10px;
        padding-left: 10px;
    }
    .attr-list {
        padding: 0 15% 0 5%;
    }
    .attr-list .layui-form-label {
        width: 280px !important;
    }
    .attr-list .layui-input-block {
        margin-left: 310px !important;
    }
    .rule-btn {
        color: #008aff;
        cursor: pointer;
        line-height: 38px;
        margin-right: 10px;
    }
    .create_variant {
        display: inline-block;
        color: #FFFFFF;
        vertical-align: middle;
        padding: 4px 6px;
        cursor: pointer;
        background-color: #1E9FFF;
        border-radius: 4px;
        margin-left: 10px;
    }
    .attr-item {
        margin: 3px 0;
    }
    .mapping-select {
        margin: 5px;
        height: 26px;
    }
    .origin-spec {
        height: 26px;
        line-height: 26px;
    }
    #attr_list_table .layui-form-selected dl {
        height: 250px; /* 设置最大高度 */
        overflow: auto; /* 超出部分可滚动 */
        min-height: 250px !important;
    }
</style>
<div class="layui-tab layui-tab-card">
    <div class="layui-tab-content" style="background-color: #F0F2F5;">
        <form action="{:sysuri()}" method="post" data-auto="true" class="layui-form layui-card" data-table-id="CollectGoods" lay-filter="goods_edit" style="background-color: #F0F2F5;" id="self_goods_add_form">

            <div class="layui-card">
                <div class="layui-card-header">{:lang('基本信息')}</div>
                <div class="layui-card-body">
                    {if !empty($account_show) }
                    <div class="layui-form-item">
                        <label class="layui-form-label label-required-next">{:lang("公司")}:</label>
                        <div class="layui-input-block">
                            <select name="account_id" class="layui-select" required lay-filter="change_account" lay-verify="required">
                                <option value="">请选择</option>
                                {if !empty($account_arr) }
                                {foreach $account_arr as $account_id => $account_name }
                                <option value="{$account_id|default=''}" >{$account_name|default=''}</option>
                                {/foreach}
                                {/if}
                            </select>
                        </div>
                    </div>
                    {/if}
                    <div class="layui-form-item">
                        <label class="layui-form-label label-required-next">{:lang('店铺')}：</label>
                        <div class="layui-input-block" >
                            <select name="shop_id" lay-filter="change_shop" lay-verify="required">
                                <option value="">请选择</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label label-required-next">{:lang('产品标题')}：</label>
                        <div class="layui-input-block">
                            <input type="text" name="title" placeholder="{:lang('请输入')}" autocomplete="off" class="layui-input" value="" lay-verify="required">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label label-required-next">{:lang('平台类目')}：</label>
                        <div class="layui-input-block" >
                            <input id="category_id" name="category_id" required lay-verify="required" placeholder="{:lang('平台类目')}" >
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label label-required-next">{:lang('库存类型')}：</label>
                        <div class="layui-input-block">
                            <input type="radio" name="mode_type" value="0" title="{:lang('单品')}" checked lay-filter="change_mode_type">
                            <input type="radio" name="mode_type" value="1" title="{:lang('多变种')}" lay-filter="change_mode_type">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">{:lang('商品单位')}：</label>
                        <div class="layui-input-block">
                            <input type="text" required lay-verify="required" name="unit_name" placeholder="{:lang('请输入单位名称')}" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label label-required-next">{:lang('商品状态')}：</label>
                        <div class="layui-input-block">
                            <input type="radio" name="is_show" value="1" title="{:lang('上架')}" >
                            <input type="radio" name="is_show" value="0" title="{:lang('下架')}" checked > 
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">{:lang('关键词')}：</label>
                        <div class="layui-input-block">
                            <input type="text" name="keyword" placeholder="{:lang('请输入关键词')}" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">{:lang('添加视频')}：</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="video_open" lay-skin="switch" lay-filter="video_open" title="{:lang('开启')}|{:lang('关闭')}">
                        </div>
                    </div>
                    <div class="video_info" style="display: none;">
                        <div class="layui-form-item">
                            <label class="layui-form-label">{:lang('视频地址')}：</label>
                            <div class="layui-input-block">
                                <input type="hidden" name="video_link">
                            </div>
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">{:lang('运费')}：</label>
                        <div class="layui-input-block">
                            <input type="number" name="postage" placeholder="{:lang('请输入运费')}" autocomplete="off" class="layui-input" min="0" lay-affix="number">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">{:lang('已售数量')}：</label>
                        <div class="layui-input-block">
                            <input type="number" name="ficti" placeholder="{:lang('请输入已售数量')}" autocomplete="off" class="layui-input" min="0" step="1" lay-affix="number">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">{:lang('购买送积分')}：</label>
                        <div class="layui-input-block">
                            <input type="number" name="give_integral" placeholder="{:lang('请输入购买送积分')}" autocomplete="off" class="layui-input" min="0" step="1" lay-affix="number">
                        </div>
                    </div>
                    <!-- <div class="layui-form-item">
                        <label class="layui-form-label">{:lang('是否单独分佣')}：</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="is_sub" lay-skin="switch" lay-filter="switchSub" title="{:lang('开启')}|{:lang('关闭')}">
                        </div>
                    </div> -->
                    <div class="layui-form-item">
                        <label class="layui-form-label">{:lang('是否限购')}：</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="is_limit" lay-skin="switch" lay-filter="is_limit" title="{:lang('开启')}|{:lang('关闭')}">
                        </div>
                    </div>
                    <div class="limit_info" style="display: none;">
                        <div class="layui-form-item">
                            <label class="layui-form-label">{:lang('限购类型')}：</label>
                            <div class="layui-input-block">
                                <input type="radio" name="limit_type" value="1" title="{:lang('单次限购')}" >
                                <input type="radio" name="limit_type" value="2" title="{:lang('永久限购')}" > 
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">{:lang('限购数量')}：</label>
                            <div class="layui-input-block">
                                <input type="number" name="limit_num" placeholder="{:lang('请输入限购数量')}" autocomplete="off" class="layui-input" min="0" step="1" lay-affix="number" >
                            </div>
                        </div>
                    </div>
                    <!-- <div class="layui-form-item">
                        <label class="layui-form-label">{:lang('会员专属')}：</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="vip_product" lay-skin="switch" lay-filter="switchVip" title="{:lang('开启')}|{:lang('关闭')}" >
                        </div>
                    </div> -->
                    <div class="layui-form-item">
                        <label class="layui-form-label">{:lang('预售商品')}：</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="presale" lay-skin="switch" lay-filter="switchPresale" title="{:lang('开启')}|{:lang('关闭')}" >
                        </div>
                    </div>
                    <div class="presale_info" style="display: none;">
                        <div class="layui-form-item">
                            <label class="layui-form-label">{:lang('预售活动时间')}：</label>
                            <div class="layui-input-block">
                                <input data-datetime-range name="presale_time" placeholder="{:lang('请选择预售时间')}" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">{:lang('发货时间')}：</label>
                            <div class="layui-form-mid">{:lang('预售活动结束后')}</div>
                            <div class="layui-input-inline">
                                <input type="number" name="presale_day" placeholder="{:lang('请输入发货时间')}" autocomplete="off" class="layui-input" min="0" step="1" lay-affix="number" >
                            </div>
                            <div class="layui-form-mid">{:lang('天之内')}</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">{:lang('商品推荐')}：</label>
                        <div class="layui-input-block">
                            {foreach $goods_recommend as $key => $val}
                            <input type="checkbox" name="{$key}" title="{$val}" lay-skin="tag"> 
                            {/foreach}
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-card" style="margin-top: 10px;">
                <div class="layui-card-header">{:lang('扩展信息')}</div>
                <div class="layui-card-body">
                    <div class="layui-form-item">
                        <label class="layui-form-label label-required-next">SPU：</label>
                        <div class="layui-input-inline" style="width: 200px;">
                            <input type="text" name="spu_code" autocomplete="off" class="layui-input" value="" readonly lay-verify="required">
                        </div>
                        <span class="rule-btn" id="spu_rule_btn">{:lang('按规则生成')}</span>
                        <span style="font-style: normal;color: #949494">{:lang('可用于同一个店铺产品去重')}</span>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">{:lang('货源URL')}：</label>
                        <div class="layui-input-block" style="display: flex;">
                            <input type="text" id="source_url" name="source_url" placeholder="{:lang('请输入')}" autocomplete="off" class="layui-input" value="">
                            <a href="javascript:;" style="width: 60px;font-size: 16px;line-height: 40px;" id="url_visit">&nbsp;&nbsp;{:lang('访 问')}</a>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">{:lang('ERP分类')}：</label>
                        <div class="layui-input-block">
                            <input class="layui-input" id="shop_category_id" name="shop_category_id" value="">
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-card" style="margin-top: 10px;">
                <div class="layui-card-header">{:lang('产品图片')}</div>
                <div class="layui-card-body">
                    <div class="layui-form-item margin-bottom-5">
                        <div class="layui-textarea help-images">
                            <input type="hidden" value="" name="goods_images">
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-card" style="margin-top: 10px;" id="change_mode_type_0">
                <div class="layui-card-header">{:lang('价格&库存')}</div>
                <div class="layui-card-body">
                    <div class="layui-form-item" style="padding-left: 10px;">
                        <span class="attr-left">{:lang('价格')}</span>
                    </div>
                    <div class="layui-row layui-col-space5">
                        <div class="layui-col-xs6">
                            <div class="layui-form-item">
                                <label class="layui-form-label label-required-next">{:lang('产品编号')}：</label>
                                <div class="layui-input-block">
                                    <input class="layui-input" name="sku[goods_nu]" value="" placeholder="{:lang('请输入')}">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs6">
                            <div class="layui-form-item">
                                <label class="layui-form-label label-required-next">{:lang('重量')}：</label>
                                <div class="layui-input-block">
                                    <input type="number" lay-affix="number" min="0" class="layui-input" name="sku[weight]" value="" placeholder="{:lang('请输入')}">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs6">
                            <div class="layui-form-item">
                                <label class="layui-form-label label-required-next">{:lang('价格')}：</label>
                                <div class="layui-input-block">
                                    <input type="number" lay-affix="number" min="0" class="layui-input" name="sku[price]" value="" placeholder="{:lang('请输入')}">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs6">
                            <div class="layui-form-item">
                                <label class="layui-form-label label-required-next">{:lang('包装长度')}：</label>
                                <div class="layui-input-block">
                                    <input type="number" lay-affix="number" min="0" class="layui-input" name="sku[length]" value="" placeholder="{:lang('请输入')}">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs6">
                            <div class="layui-form-item">
                                <label class="layui-form-label label-required-next">{:lang('原价')}：</label>
                                <div class="layui-input-block">
                                    <input type="number" lay-affix="number" min="0" class="layui-input" name="sku[sale_price]" value="" placeholder="{:lang('请输入')}">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs6">
                            <div class="layui-form-item">
                                <label class="layui-form-label label-required-next">{:lang('包装宽度')}：</label>
                                <div class="layui-input-block">
                                    <input type="number" lay-affix="number" min="0" class="layui-input" name="sku[width]" value="" placeholder="{:lang('请输入')}">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs6">
                            <div class="layui-form-item">
                                <label class="layui-form-label label-required-next">{:lang('成本')}：</label>
                                <div class="layui-input-block">
                                    <input type="number" lay-affix="number" min="0" class="layui-input" name="sku[cost]" value="" placeholder="{:lang('请输入')}">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs6">
                            <div class="layui-form-item">
                                <label class="layui-form-label label-required-next">{:lang('包装高度')}：</label>
                                <div class="layui-input-block">
                                    <input type="number" lay-affix="number" min="0" class="layui-input" name="sku[height]" value="" placeholder="{:lang('请输入')}">
                                </div>
                            </div>
                        </div>
                    </div>

                    <hr>
                    <div class="layui-form-item" style="padding-left: 10px;">
                        <span class="attr-left">{:lang('库存')}</span>
                    </div>
                    <div class="attr-list">
                        <div class="layui-form-item">
                            <label class="layui-form-label label-required-next">{:lang('库存')}：</label>
                            <div class="layui-input-block">
                                <input type="number" lay-affix="number" min="0" class="layui-input" name="sku[stock]" value="" placeholder="{:lang('请输入')}">
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-card specifications" style="margin-top: 10px;display: none;" id="change_mode_type_1">
                <div class="layui-card-header">{:lang('产品规格')}</div>
                <div class="layui-card-body">
                    <!-- sku参数表 -->
                    <div class="layui-form-item">
                        <label class="layui-form-label">{:lang('规格')}：</label>
                        <div class="layui-input-block">
                            <div id="fairy-spec-table"></div>
                        </div>
                    </div>

                    <!-- 动态sku表 -->
                    <div class="layui-form-item">
                        <label class="layui-form-label">{:lang('SKU表')}：</label>
                        <div class="layui-input-block">
                            <div id="fairy-sku-table"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-card" style="margin-top: 10px;">
                <div class="layui-card-header">{:lang('产品描述')}</div>
                <div class="layui-card-body">
                    <blockquote class="layui-elem-quote">{:lang('简单描述')}</blockquote>
                    <textarea name="short_desc" placeholder="{:lang('请输入内容')}"  rows="15" maxlength="5000" class="layui-textarea" style="white-space: nowrap;"></textarea>
                    <blockquote class="layui-elem-quote" style="margin-top: 10px;">{:lang('详细描述')}</blockquote>
                    <textarea name="long_desc" placeholder="{:lang('请输入内容')}" class="layui-textarea"></textarea>
                </div>
            </div>

            <div class="hr-line-dashed"></div>

            <div class="layui-form-item text-center">
                {if empty($account_show) }
                <input type="hidden" name="account_id" value="{$shop_account|default=0}">
                {/if}
                <input type="hidden" name="platform_id" value="{$platform_id|default=0}">
                <button class="layui-btn" lay-submit lay-filter="add-submit">{:lang("保存数据")}</button>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                </div>
            </div>
        </form>
    </div>
</div>
{block name="script"}
<link rel="stylesheet" href="__ROOT__/static/plugs/layui_exts/layCascader.css">
<script>
    let account_show = '{$account_show|default=0}';
    // 组图组件
    $('[name=goods_images]').uploadMultipleImage();
    // 上传视频
    $('[name=video_link]').uploadOneVideo();
    // 富文本组件
    // 异步加载富文本编辑器
    require(['ckeditor'], function () {
        setTimeout(function () {
            // 初始化富文本编辑器
            window.createEditor('[name=long_desc]', {height: 500});
        },500)
    });

    layui.use(['form', 'skuTable', 'layCascader', 'xmSelect'], function () {
        let form = layui.form, skuTable = layui.skuTable, xmSelect = layui.xmSelect;
        let table = layui.table;
        //注意！！！ 注意！！！ 注意！！！
        //如果配置了相关接口请求的参数，请置本示例于服务器中预览，不然会有浏览器跨域问题
        //示例中的json文件仅做格式返回参考，若多次执行添加规格后再为新增后的规格添加规格值，会发现所有新增的规格都增加了该规格值。注意！此处并非是bug，原因是因为示例中返回的新增规格值id是重复的，而在正常接口请求每次返回的新增规则id是不一样的
        let skuTable_obj = skuTable.render({
            //规格表容器id
            specTableElemId: 'fairy-spec-table',
            //sku表容器id
            skuTableElemId: 'fairy-sku-table',
            //sku索引分隔符
            skuNameDelimiter: ',',
            //sku表相同属性值是否合并行
            rowspan: true,
            //上传接口地址
            //接口要求返回格式为 {"code": 200, "data": {"url": "xxx"}, "msg": ""}
            uploadUrl: './json/upload.json',
            //添加规格接口地址，如果为空则表示不允许增加规格
            //接口要求返回格式为 {"code": 200, "data": {"id": "xxx"}, "msg": ""}
            specCreateUrl: './json/specCreate.json',
            //添加规格时的额外参数
            // specCreateParams: {goods_id : 888},
            //删除规格接口地址，如果为空则表示仅前端删除
            // specDeleteUrl: './json/specDelete.json',
            //添加规格值接口地址，如果为空则表示不允许增加规格值
            //接口要求返回格式为 {"code": 200, "data": {"id": "xxx"}, "msg": ""}
            specValueCreateUrl: './json/specValueCreate.json',
            createVariant: false, // 显示生成变种按钮
            //sku表格配置参数
            skuTableConfig: {
                thead: [
                    {title: '{:lang("图片")}', icon: ''},
                    {title: '{:lang("产品编号")}', icon: ''},
                    {title: '{:lang("售价")}(CNY)', icon: 'layui-icon-cols'},
                    {title: '{:lang("原价")}(CNY)', icon: 'layui-icon-cols'},
                    {title: '{:lang("成本")}(CNY)', icon: 'layui-icon-cols'},
                    {title: '{:lang("库存")}', icon: 'layui-icon-cols'},
                    {title: '{:lang("长")}(cm)', icon: 'layui-icon-cols'},
                    {title: '{:lang("宽")}(cm)', icon: 'layui-icon-cols'},
                    {title: '{:lang("高")}(cm)', icon: 'layui-icon-cols'},
                    {title: '{:lang("重(g)")}', icon: 'layui-icon-cols'},
                ],
                tbody: [
                    {type: 'image', field: 'image', value: '', verify: 'required', reqtext: 'sku图片不能为空'},
                    {type: 'input', field: 'goods_nu', value: '', verify: 'required',reqtext: '产品编号不能为空'},
                    {type: 'input', field: 'price', value: '0', verify: 'required|number', reqtext: '{:lang("售价不能为空")}'},
                    {type: 'input', field: 'sale_price', value: '0', verify: 'required|number', reqtext: '{:lang("原价不能为空")}'},
                    {type: 'input', field: 'cost', value: '0', verify: 'required|number', reqtext: '{:lang("成本不能为空")}'},
                    {type: 'input', field: 'stock', value: '0', verify: 'required|number', reqtext: '{:lang("库存不能为空")}'},
                    {type: 'input', field: 'length', value: '0', verify: 'number', reqtext: ''},
                    {type: 'input', field: 'width', value: '0', verify: 'number', reqtext: ''},
                    {type: 'input', field: 'height', value: '0', verify: 'number', reqtext: ''},
                    {type: 'input', field: 'weight', value: '0', verify: 'number', reqtext: ''},
                ]
            },
            //规格数据, 一般从后台获取
            specData: [],
            skuData: [],
        });

        form.on('submit(add-submit)', function (obj) {
            let data = obj.field;
            data.specData = skuTable_obj.getSpecData();

            // 数据验证
            if(!isNotEmpty(data.shop_id)) {
                $.msg.error('{:lang("请选择店铺")}');
                return false;
            }
            if(!isNotEmpty(data.title)) {
                $.msg.error('{:lang("产品标题不能为空")}');
                return false;
            }
            if(!isNotEmpty(data.spu_code)) {
                $.msg.error('{:lang("SPU不能为空")}');
                return false;
            }
            if(!isNotEmpty(data.category_id)) {
                $.msg.error('{:lang("请选择分类")}');
                return false;
            }
            if(!isNotEmpty(data.mode_type)) {
                $.msg.error('{:lang("请选择库存类型")}');
                return false;
            }
            if(!isNotEmpty(data.unit_name)) {
                $.msg.error('{:lang("请选择商品单位")}');
                return false;
            }
            // if(!isNotEmpty(data.is_show)) {
            //     $.msg.error('{:lang("请选择商品状态")}');
            //     return false;
            // }
            if(data.mode_type == 1){
                if(!isNotEmpty(data.specData)) {
                    $.msg.error('{:lang("请设置商品规格属性")}');
                    return false;
                }
            }

            httpRequest('{:url("add")}', data, 'post', function(msg, res) {
                $.msg.success(msg, 2, function () {
                    $.msg.closeThisModal('#self_goods_add_form')
                })
            })
            return false
        })

        // 选择sku类型
        form.on('radio(change_mode_type)', function(obj) {
            if(obj.value === '1') { // 多变种
                $('#change_mode_type_1').show();
                $('#change_mode_type_0').hide();
            } else { // 单品
                $('#change_mode_type_1').hide();
                $('#change_mode_type_0').show();
            }
        });

        // 选择添加视频
        form.on('switch(video_open)', function(obj) {
            if(obj.elem.checked){
                $('.video_info').show();
            }else{
                $('.video_info').hide();
            }
        });

        // 选择是否限购
        form.on('switch(is_limit)', function(obj) {
            if(obj.elem.checked){
                $('.limit_info').show();
            }else{
                $('.limit_info').hide();
            }
        });

        //选择是否预售
        form.on('switch(switchPresale)', function(obj) {
            if(obj.elem.checked){
                $('.presale_info').show();
            }else{
                $('.presale_info').hide();
            }
        });

        // 选择平台分类
        let layCascader = layui.layCascader;
        let category_id = 0;
        let category_data = [];

        let category_change = layCascader({
            elem:  "#category_id"
            ,placeholder: "{:lang('不选默认顶级分类')}"
            ,clearable: true
            ,value: category_id
            ,props: {
                value: 'cate_id',
                label: 'name',
                children: 'children',
                multiple: true
            }
            ,filterable: true
            ,options: category_data
        });

        let shop_category_id = 0;
        let shop_category_data = JSON.parse('{:json_encode($shop_category_list)}');
        // 选择erp分类
        let erp_category_change = layCascader({
            elem:  "#shop_category_id"
            ,placeholder: "{:lang('不选默认顶级分类')}"
            ,clearable: true
            ,value: shop_category_id
            ,props: {
                value: 'id',
                label: 'title',
                children: 'children'
            }
            ,filterable: true
            ,options: shop_category_data
        });

        $('#url_visit').on('click', function() {
            let source_url = $('#source_url').val();
            if(!isNotEmpty(source_url)) {
                return false;
            }
            layui.util.openWin({'url':source_url})
        })

        // 生成SPU
        $('#spu_rule_btn').on('click', function() {
            httpRequest('{:url("createSPU")}', {}, 'get', function(msg, res) {
                if(isNotEmpty(res)) {
                    $('input[name="spu_code"]').val(res);
                } else {
                    layer.msg('{:lang("生成失败")}', {icon: 2});
                }
            })
        });

        if(account_show == 1){
            form.on('select(change_account)', function(obj) {
                let account = obj.value;
                let f_data = form.val('goods_edit');
                getShopList(account, f_data.platform_id)
                getCategoryList(category_change)
            })
        }else{
            let ff_data = form.val('goods_edit');
            getShopList(ff_data.account_id, ff_data.platform_id)
            getCategoryList(category_change)
        }
    });

    function getShopList(account_id = 0, platform_id = 0) {
        $.ajax({
            url: "{:sysuri('common/ajax/getShopList')}",
            type: 'post',
            data: {'account_id':account_id, 'platform_id':platform_id},
            dataType: 'json',
            success: function(res) {
                if (res.code == 1) {
                    let data = res.data;
                    let html = '<option value="">{:lang("请选择")}</option>';
                    for (let i = 0; i < data.length; i++) {
                        html += '<option value="' + data[i].id + '">' + data[i].name + '</option>';
                    }
                    $('select[name="shop_id"]').html(html);
                    form.render('select');
                }else{
                    $.msg.error(res.info)
                    return false;
                }
            },
            error: function(err){
                $.msg.error(err.status + err.statusText);
            }
        })
    }

    function getCategoryList(category_change){
        // 请求获取平台分类
        httpRequest('{:url("getCategoryList")}', {'account_id':form.val('goods_edit').account_id}, 'post', function(msg, res) {
            layui.each(res, function(index, item) {
                if(!isNotEmpty(item.children)){
                    item.disabled = 'disabled'
                }
            });
            category_change.setOptions(res);
        });
    }

    // 处理下拉菜单超出的问题
    function setWidth() {
        setTimeout(function() {
            let width_list = $('#feature_list .layui-form-item .layui-input-block');
            if(isNotEmpty(width_list) && isNotEmpty(width_list[0])) {
                let width = width_list[0].clientWidth;
                $('#feature_list .xm-option-content').width(width - 60);
            }
        }, 500)
    }
</script>
{/block}